<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Reg extends CI_Controller {
	function __construct(){
		parent::__construct();
		
	}
	
	function index(){
		if($this->input->post('act') == 'reg'){
			$ret['url_title'] = '返回注册';
			$ret['url_next']="javascript:history.go(-1)";
			$pw = $this->input->post ( 'password' );
			$invite = trim ( $this->input->post ( 'invite' ) );
			$this->load->model ( 'User_model', 'user' );
			$invite_info = $this->user->get_one ( array ('user_id' => $invite ), 'user_id' );
			$invite_userid = 0;
			if ($invite_info) {
				$invite_userid = $invite_info ['user_id'];
			}
			$data = array ('username' => trim ( $this->input->post ( 'phone' ) ),  'password' => md5 ( md5 ( $pw ) ), 'phone' => trim ( $this->input->post ( 'phone' ) ), 'invite_userid' => intval ( $invite_userid ), 
				'type_id' => '2', 'add_time' => time (), 'addip' => $this->input->ip_address ());
			/*if ($data ['username'] == "") {
				$ret ['msg'] = '会员昵称不能为空';
			} elseif (! isset ( $data ['username'] [4] ) && ! isset ( $data ['username'] [16] )) {
				$ret ['msg'] = '会员昵称长度不合法，4至16之间';
			} elseif (! $this->myformcheck->isName ( $data ['username'].'18' )) {
				$ret ['msg'] = '无效会员昵称，必须含有字母，其中只允许0~9!#$^&?_字符';
			}  else*/if (  strlen($pw)<6 || strlen($pw)>20){
				$ret ['msg'] = '密码长度不合法，6至20之间';
			}elseif ($pw == "" || !$this->myformcheck->isName($pw) ) {
				$ret ['msg'] = '无效密码，必须含有数字+字母，其中只允许~!#$^&?_字符';
			} elseif ($pw != $this->input->post ( 'password2' )) {
				$ret ['msg'] = '两次密码不一致';
			} elseif (! $this->myformcheck->isPhone ( $data ['phone'] )) {
				$ret ['msg'] = '请填写有效的手机号码'. $data ['phone'] ;
			}else{
				//手机验证码
				$verify_code = $this->input->post ( 'verify_code' );
				$md5 = $this->session->userdata ( $data ['phone'] );
				
	
				
				if ($verify_code != $md5) {
					$ret ['msg'] = '手机验证码不正确';
				} elseif ($this->user->get_one ( array ('username' => $data ['username'] ), 'user_id' )) {
					$ret ['msg'] = '会员昵称已存在';
				}else{
					
					//echo $ret ['msg']."dd1";exit;
					$data ['phone_status'] = 1;
					$data ['smscode'] = $md5;
					$data ['smstime'] = time();
					$data ['uptime'] = $data ['smstime'];
					$data ['lasttime'] = $data ['smstime'];
					
					//添加注册信息到用户表
					$user_id = $this->user->add ( $data );
					
					if ($user_id > 0) {
						//发送邮件
						//$res = $this->notice_email ( $user_id );
						//添加注册积分日志并修改积分
						//$this->notice_credit( $user_id, 'reg' );
						//手机积分日志
						//$this->notice_credit ( $user_id, 'phone' ); 
						
						//初始化资金账号
						$this->load->model('Account_model', 'redaccount');
						$initAccount = array('user_id'  => $user_id,'total'=> '0','use_money'=>'0','no_use_money' =>'0','collection'=> '0','red_money'=>'0');
						$this->redaccount->init_account($initAccount);
				
						//发放代金券
						$this->load->model('Redmanagement_model', 'redmanagement');
						$this->redmanagement->send_red($user_id,1,"注册");
						if($invite_userid > 0){
							//发放代金券
							$this->redmanagement->send_red($invite_userid,10,"好友邀请".$user_id);
						}
						//注册成功自动登陆
						$user = array ('user_id' => $user_id, 'username' => $data ['username'], 'email' => $data ['email'], 'login_time' => time () );
						$this->session->set_userdata ( 'rsh_user', $user );
						$ret['msg'] = '注册成功，进行实名认证，尊享更多优惠';
						$ret['url_title'] = '前往用户中心';
						$ret['url_next']="/zhs_mobile/ucenter.html";
					} else {
						$ret ['msg'] = '注册失败，请稍候再试';
					}
				}
			}
			$this->load->view('zhs_mobile/msg',$ret);
		}else{
			if (isset ( $_COOKIE ['inviteRequest'] ) && $_COOKIE ['inviteRequest']) {
				$inviteRequest = $_COOKIE ['inviteRequest'];
				$data ['invite'] = $inviteRequest;
			}
			elseif(isset($_GET["invite"])){
				$inviteRequest = $_GET["invite"];
				setcookie("inviteRequest",$inviteRequest, time()+3600);
				$data ['invite'] = $inviteRequest;
			}
			$data['tab'] = 2;
			
			$this->load->view('zhs_mobile/reg',$data);
		}
	}
	
=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Reg extends CI_Controller {
    function __construct(){
		parent::__construct();
		
	}
	
	function index(){
		if($this->input->post('act') == 'reg'){
			$ret['url_title'] = '返回注册';
			$ret['url_next']="javascript:history.go(-1)";
			$pw = $this->input->post ( 'password' );
			$invite = trim ( $this->input->post ( 'invite' ) );
			$this->load->model ( 'User_model', 'user' );
			$invite_info = $this->user->get_one ( array ('user_id' => $invite ), 'user_id' );
			$invite_userid = 0;
			if ($invite_info) {
				$invite_userid = $invite_info ['user_id'];
			}
			$data = array ('username' => trim ( $this->input->post ( 'phone' ) ),  'password' => md5 ( md5 ( $pw ) ), 'phone' => trim ( $this->input->post ( 'phone' ) ), 'invite_userid' => intval ( $invite_userid ), 
				'type_id' => '2', 'add_time' => time (), 'addip' => $this->input->ip_address ());
			/*if ($data ['username'] == "") {
				$ret ['msg'] = '会员昵称不能为空';
			} elseif (! isset ( $data ['username'] [4] ) && ! isset ( $data ['username'] [16] )) {
				$ret ['msg'] = '会员昵称长度不合法，4至16之间';
			} elseif (! $this->myformcheck->isName ( $data ['username'].'18' )) {
				$ret ['msg'] = '无效会员昵称，必须含有字母，其中只允许0~9!#$^&?_字符';
			}  else*/if (  strlen($pw)<6 || strlen($pw)>20){
				$ret ['msg'] = '密码长度不合法，6至20之间';
			}elseif ($pw == "" || !$this->myformcheck->isName($pw) ) {
				$ret ['msg'] = '无效密码，必须含有数字+字母，其中只允许~!#$^&?_字符';
			} elseif ($pw != $this->input->post ( 'password2' )) {
				$ret ['msg'] = '两次密码不一致';
			} elseif (! $this->myformcheck->isPhone ( $data ['phone'] )) {
				$ret ['msg'] = '请填写有效的手机号码'. $data ['phone'] ;
			}else{
				//手机验证码
				$verify_code = $this->input->post ( 'verify_code' );
				$md5 = $this->session->userdata ( $data ['phone'] );
				
	
				
				if ($verify_code != $md5) {
					$ret ['msg'] = '手机验证码不正确';
				} elseif ($this->user->get_one ( array ('username' => $data ['username'] ), 'user_id' )) {
					$ret ['msg'] = '会员昵称已存在';
				}else{
					
					//echo $ret ['msg']."dd1";exit;
					$data ['phone_status'] = 1;
					$data ['smscode'] = $md5;
					$data ['smstime'] = time();
					$data ['uptime'] = $data ['smstime'];
					$data ['lasttime'] = $data ['smstime'];
					
					//添加注册信息到用户表
					$user_id = $this->user->add ( $data );
					
					if ($user_id > 0) {
						//发送邮件
						//$res = $this->notice_email ( $user_id );
						//添加注册积分日志并修改积分
						//$this->notice_credit( $user_id, 'reg' );
						//手机积分日志
						//$this->notice_credit ( $user_id, 'phone' ); 
						
						//初始化资金账号
						$this->load->model('Account_model', 'redaccount');
						$initAccount = array('user_id'  => $user_id,'total'=> '0','use_money'=>'0','no_use_money' =>'0','collection'=> '0','red_money'=>'0');
						$this->redaccount->init_account($initAccount);
				
						//发放代金券
						$this->load->model('Redmanagement_model', 'redmanagement');
						$this->redmanagement->send_red($user_id,1,"注册");
						if($invite_userid > 0){
							//发放代金券
							$this->redmanagement->send_red($invite_userid,10,"好友邀请".$user_id);
						}
						//注册成功自动登陆
						$user = array ('user_id' => $user_id, 'username' => $data ['username'], 'email' => $data ['email'], 'login_time' => time () );
						$this->session->set_userdata ( 'rsh_user', $user );
						$ret['msg'] = '注册成功，进行实名认证，尊享更多优惠';
						$ret['url_title'] = '前往用户中心';
						$ret['url_next']="/zhs_mobile/ucenter.html";
					} else {
						$ret ['msg'] = '注册失败，请稍候再试';
					}
				}
			}
			$this->load->view('zhs_mobile/msg',$ret);
		}else{
			if (isset ( $_COOKIE ['inviteRequest'] ) && $_COOKIE ['inviteRequest']) {
				$inviteRequest = $_COOKIE ['inviteRequest'];
				$data ['invite'] = $inviteRequest;
			}
			elseif(isset($_GET["invite"])){
				$inviteRequest = $_GET["invite"];
				setcookie("inviteRequest",$inviteRequest, time()+3600);
				$data ['invite'] = $inviteRequest;
			}
			$data['tab'] = 2;
			
			$this->load->view('zhs_mobile/reg',$data);
		}
	}
	
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
}